package edu.java.texbooks.scjp.collections.test05.converting.array.to.list;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Test {
	public static void main(String[] args) {
		// conversion
		test01();

		// test lists
		// test02();

	}

	public static void test01() {

		// Convertion from Array to List. We use atList() method

		String[] stringArray = { "one", "three", "four", "nine" };
		List<String> stringList = Arrays.asList(stringArray);

		// print array
		System.out.println("Array print: " + Arrays.toString(stringArray));
		System.out.println("Array size: " + stringArray.length);

		// print list
		System.out.println("\n\n");
		System.out.println("List print: " + stringList);
		System.out.println("List size: " + stringList.size());

		// modification on array
		stringArray[0] = "eleven";

		// modification on list

		// it is impossible to change the count of the elements in the list. It
		// will throw an Exception
		// stringList.add("twelve");
		// stringList.clear();
		// stringList.remove(0);

		System.out.println("Array size: " + stringArray.length);
		stringList.set(1, "five");

		// print array and list
		System.out.println("\n--------------------------");
		System.out.println("Array print: " + Arrays.toString(stringArray));
		System.out.println("\n");
		System.out.println("List print: " + stringList);

	}

	public static void test02() {
		List<String> list1 = new ArrayList<String>();
		list1.add("java");
		list1.add("c#");

		List<String> list2 = new ArrayList<String>(list1);

		System.out.println("\n" + "list1: " + list1);
		System.out.println("\n" + "list2: " + list2);

		System.out.println("-----------------------");
		list1.add("c++");
		list2.set(0, "delphi");

		System.out.println("\n" + "list1: " + list1);
		System.out.println("\n" + "list2: " + list2);

		// Conclusion: when we add list in the consrtuctor of collection, the
		// argument object is not shared

	}
}